package controllers

import (
	//ex "errors"
	"github.com/revel/revel"
	"waterblabla/app/models"
)

type Usr struct {
	Controller
}

// 设备提交绑定请求
func (c Usr) Call() revel.Result {
	// parse
	type Req struct {
		Sn string
		Count int
	}
	
	var req Req
	if err := models.ParseBodyAndValidate(c.body, &req); err != nil {
		return c.RenderResult(err)
	}
	// determine wether the specified sn is ours by check device
	if err := models.ValidateSn(req.Sn); err != nil {
		return c.RenderResult(err)
	}

	return c.RenderResult(models.AddOrderWithCount(req.Sn, req.Count))
}


